export const METHOD_METADATA = 'method'
export const PATH_METADATA = 'path'
export const REQUEST_ARGS_METADATA = 'request_args'

export interface RequestArgs {
  query: string[]
  body: string[]
}

export const Controller = (path: string): ClassDecorator => {
  return (target) => {
    Reflect.defineMetadata(PATH_METADATA, path, target)
  }
}

const createMappingDecorator = (method: string) => {
  return (path: string, args?: RequestArgs): MethodDecorator => {
    return (_target, _key, descriptor) => {
      Reflect.defineMetadata(REQUEST_ARGS_METADATA, JSON.stringify(args), descriptor.value!)
      Reflect.defineMetadata(PATH_METADATA, path, descriptor.value!)
      Reflect.defineMetadata(METHOD_METADATA, method, descriptor.value!)
    }
  }
}

export const Get = createMappingDecorator('GET')
export const Post = createMappingDecorator('POST')
